package top.rainf.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.rainf.domain.vo.UserBaseInfo;
import top.rainf.mapper.UserBaseInfoMapper;
import top.rainf.service.IUserBaseInfoService;
import top.rainf.util.MD5Util;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 星环
 * @date 2023/5/9 18:43:45
 * @description
 */

@Service
public class UserBaseInfoService implements IUserBaseInfoService {

    @Autowired
    UserBaseInfoMapper userBaseInfoMapper;

    @Override
    public boolean resetPasswordByUsername(String username, String newPassword) {
        String password = MD5Util.encode(newPassword);
        int i = userBaseInfoMapper.updatePasswordByUsername(username, password);
        return i == 1;
    }

    @Override
    public List<UserBaseInfo> getUserBaseInfoList() {
        return userBaseInfoMapper.selectAll();
    }

    @Override
    public UserBaseInfo getOneById(int id) {
        return userBaseInfoMapper.selectUserBaseInfoById((long) id);
    }

    @Override
    public boolean deleteOneById(int id) {
        return false;
    }

    @Override
    public boolean deleteAll(List<Integer> idList) {
        return false;
    }

    @Override
    public boolean updateById(UserBaseInfo userBaseInfo) {
        return false;
    }

    @Override
    public List<UserBaseInfo> getByIds(List<Integer> uidList) {
        return userBaseInfoMapper.selectByIds(uidList);
    }

    @Override
    public UserBaseInfo getByUsername(String username) {
        return userBaseInfoMapper.selectUserBaseInfoByUsername(username);
    }

    @Override
    public List<Integer> getIdByUsernames(List<String> atUsers) {
        if(atUsers.size() == 0){
            return new ArrayList<>( );
        }
        return userBaseInfoMapper.selectIdByUsernames(atUsers);
    }

    @Override
    public List<UserBaseInfo> srchByUsernameExcept(String username, int userId) {
        UserBaseInfo userBaseInfo = new UserBaseInfo();
        userBaseInfo.setUsername(username);
        List<UserBaseInfo> userBaseInfos = userBaseInfoMapper.selectUserBaseInfoList(userBaseInfo);
        return userBaseInfos;
    }
}
